Skip to content

feat: add max, min, ceil & floors operators#180

Open
aoustry wants to merge 12 commits intomainfrom
claude/variadic-max-min-operators-tRF8C
Open

feat: add max, min, ceil & floors operators#180
aoustry wants to merge 12 commits intomainfrom
claude/variadic-max-min-operators-tRF8C

Conversation

@aoustry
Copy link
Collaborator

@aoustry aoustry commented Mar 20, 2026

No description provided.

claude added 12 commits March 18, 2026 21:45
These operators are needed to parse and evaluate GEMS model expressions
from antares_legacy_models.yml, which uses ceil(p/q), max(0, expr), and
min(a, b) in variable bounds and constraint expressions for thermal unit
commitment models.

Changes:
- Add FloorNode, CeilNode (unary) and MaxNode, MinNode (binary) AST nodes
- Add floor()/ceil() methods on ExpressionNode; maximum()/minimum() factory fns
- Extend Expr.g4 grammar with binaryFunction rule; regenerate ANTLR files
- Update all visitors: abstract ExpressionVisitor, CopyVisitor, PrinterVisitor,
  EvaluationVisitor, ExpressionDegreeVisitor, TimeScenarioIndexingVisitor,
  EqualityVisitor
- Register floor/ceil in _FUNCTIONS and max/min in new _BINARY_FUNCTIONS dict
- Add tests for parsing, evaluation, and printing of the new operators

https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC
…ExpressionBuilder

Add ceil, floor, maximum, minimum implementations to all ExpressionVisitor
subclasses that were missing them after the new math operators were added.

https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC
floor(x), ceil(x), max(x,y), min(x,y) are not polynomials when their
operands involve variables, so their degree is mathematically undefined
(infinity) rather than equal to the operand degree.

Also widens ExpressionDegreeVisitor and compute_degree from int to
int | float to accommodate math.inf.

https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC
…| float

When ExpressionDegreeVisitor is parameterized as ExpressionVisitor[int | float],
visit() returns int | float everywhere, so all methods that call visit() and
were annotated -> int now need -> int | float.

https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC
…st grammar rule

Replace the separate binaryFunction grammar rule with a unified function rule
using argList, allowing max/min to accept an arbitrary number of operands.

Changes:
- grammar/Expr.g4: add argList rule, merge function/binaryFunction into single
  IDENTIFIER '(' argList? ')' # function rule
- Regenerate ANTLR parser files from updated grammar
- expression.py: change MaxNode/MinNode from BinaryOperatorNode to variadic
  nodes with operands: List[ExpressionNode]; update maximum()/minimum() helpers
  to accept *args
- parse_expression.py: merge visitBinaryFunction into visitFunction using
  argList context; remove separate _BINARY_FUNCTIONS dict
- All visitor implementations updated to use node.operands instead of
  node.left/node.right (evaluate, print, degree, copy, equality, indexing,
  port)
- Tests: add variadic test cases (3+ operands) for parsing, degree, evaluation,
  and printer

https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3
isort requires stdlib imports (sys, io) before third-party (antlr4)
in the generated ExprLexer.py, ExprParser.py, and ExprVisitor.py.

https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3
Black reformats ExprLexer.py, ExprParser.py and ExprVisitor.py:
spaces after colons in type hints, one-item-per-line lists, extra
blank lines between class/function definitions.

https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants